# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ogitor
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=r816.cf42232
pkgrel=1
pkgdesc="WYSIWYG scene editing environment for OGRE (mingw-w64)"
arch=('any')
url="https://www.ogre3d.org/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "git")
depends=("${MINGW_PACKAGE_PREFIX}-libwinpthread"
         "${MINGW_PACKAGE_PREFIX}-ogre3d"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-qt5")
options=('staticlibs' '!strip' '!buildflags')
source=("${_realname}::git+https://github.com/OGRECave/ogitor.git"
        ogre-pagedgeometry::git+https://github.com/OGRECave/ogre-pagedgeometry.git
        QtPropertyBrowser::git+https://github.com/bazhenovc/QtPropertyBrowser.git
        Hydrax.zip
        OgreCore.zip
        SkyX.zip
        SO3Deferred.zip
        SO3SelectionBuffer.zip
        000-creating-translations.patch
        001-dont-install-3rdparty-libraries.patch
        002-install-layout.patch
        003-fix-samples-destination.patch
        004-fix-plugin-name-for-ogre.patch
        050-pagedgeometry-msvc-stuff.patch
        051-gettickcount-declaration.patch
        052-install-files.patch)
sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            '1616c72e07bf2b9f071b9a5a33f2bf59dd0eebfc86f1f010a8bb7c3a3e7a579e'
            '9c6903c8f5dadf10f7c9aa8dad94d58c6da6e9dffa1874dc3531e643f97c9d03'
            'c45c0d5815f1909e9c59f57bae9b75864119bfc069bb447ea7adb5c9571a6230'
            'e60ca5aae39bd801b07340576caef8d3b1351e7426cfb41422be8ff5624f2ef4'
            '495c01d952888aee4a2c90e30d0c4113d18a506824e0f24d114d7464c3c1728e'
            '6d206b6d03fc4931901093a45a9c3b9762c187d81c9c5fbd11c590f8b4c67bf4'
            '9e3ce86d3ce06ea8d3ab935e185a19cff3e9996b8e7424e17eafed11edcb6482'
            'adb01084f0cb9eba7864ff4628a03292c33a94de5e347fdb3e436de9be3b7e83'
            '0529545c363bdb656c4d8049d20eda367d57c73d1b7b37f757dcecf12e965ade'
            '72f8c637aa0e5c62a8b5a12b7a7b6948b9769f555e4f18614f92f6b045676a69'
            '07ed202e28ae12aa48dc5a23601cb2b0b18548b4745028b5ee61c78de3db2f22'
            'b293f9c887a3868fc6429e7e21e79ee651d0f3fa1a2876fe6314fd06407f5be2'
            '6510fae2f0ea627216ce954f55bdcae78827589becb56549cd92f63a2dc1f077')
noextract=(Hydrax.zip
           OgreCore.zip
           SkyX.zip
           SO3Deferred.zip
           SO3SelectionBuffer.zip)

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ogre-pagedgeometry
  patch -p1 -i ${srcdir}/050-pagedgeometry-msvc-stuff.patch
  patch -p1 -i ${srcdir}/051-gettickcount-declaration.patch
  patch -p1 -i ${srcdir}/052-install-files.patch
  cd ..
  cp -rf ogre-pagedgeometry/* ${_realname}/Dependencies/pagedgeometry/
  cp -rf QtPropertyBrowser/*  ${_realname}/qtOgitor/QtPropertyBrowser/
  cd "${srcdir}/${_realname}"
  patch -p1 -i ${srcdir}/000-creating-translations.patch
  patch -p1 -i ${srcdir}/001-dont-install-3rdparty-libraries.patch
  patch -p1 -i ${srcdir}/002-install-layout.patch
  patch -p1 -i ${srcdir}/003-fix-samples-destination.patch
  patch -p1 -i ${srcdir}/004-fix-plugin-name-for-ogre.patch
}

build() {
  local -a extra_config
  if check_option "debug" "y"; then
    extra_config+=( -DCMAKE_BUILD_TYPE=Debug )
  else
    extra_config+=( -DCMAKE_BUILD_TYPE=Release )
  fi

  rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX" \
  OGRE_HOME=${MINGW_PREFIX} \
  QTDIR=${MINGW_PREFIX} \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    ../${_realname}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" -j1 install

  cp -f ${srcdir}/Hydrax.zip ${pkgdir}${MINGW_PREFIX}/share/ogitor/Media/packs/
  cp -f ${srcdir}/OgreCore.zip ${pkgdir}${MINGW_PREFIX}/share/ogitor/Media/packs/
  cp -f ${srcdir}/SkyX.zip ${pkgdir}${MINGW_PREFIX}/share/ogitor/Media/packs/
  cp -f ${srcdir}/SO3Deferred.zip ${pkgdir}${MINGW_PREFIX}/share/ogitor/Media/packs/
  cp -f ${srcdir}/SO3SelectionBuffer.zip ${pkgdir}${MINGW_PREFIX}/share/ogitor/Media/packs/
}
